<%@page language="java" isELIgnored="false" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<jsp:directive.include file="/WEB-INF/sitemesh-decorators/include.jsp"/>
<fmt:setBundle basename="bundles.thesis-resources"/>
<html>
<head>
<title>Edit <fmt:message key="thesis.title"/> <fmt:message key="category.title"/></title>

<script type="text/javascript">
var tempStr2="";
$(function() {
	var categoryList = '${categoryList}';
	var catStr = categoryList.substring(categoryList.indexOf('{')+1,categoryList.indexOf('}'));
	catStr = catStr.replace(/=/g,":");
	//alert(catStr);
	var categoryArr=catStr.split(',');
	var tempArray = new Array();
	var tempStr="";
	for(var i=0;i<categoryArr.length;i++){
		tempStr = categoryArr[i];
		tempStr = tempStr.substring(tempStr.indexOf(":")+1);
		//alert(tempStr);
		tempArray[i]= tempStr;
	}
	var tempStr1="";
	
	
	$( "#category_categoryDescription").autocomplete({
		//source: categoryArr,
		source: tempArray,
		//define select handler
		select: function(e, ui) {
			//create formatted data
			var cat = ui.item.value;
			getId(cat,categoryArr);
			
			$("#category_categoryDescription").val(cat);
			//tempStr1 = cat.substring(cat.indexOf(":")+1);
			//alert(tempStr1);
			//tempStr2 = cat.substring(0,cat.indexOf(":"));
			//alert(tempStr2);
		},
		close: function(event, ui) {
			
			
		}
	});
	
});
//if(tempStr2=="")
//	$("#category_categoryId").val(tempStr2);
	
function getId(str,arr){
	var key = "";
	var value ="";
	var tempStr="";
	for(var i=0;i<arr.length;i++){
		tempStr = arr[i];
		key=tempStr.substring(0,tempStr.indexOf(":"));
		value = tempStr.substring(tempStr.indexOf(":")+1);
		if(value==str){
			//alert(key);
			$("#category_categoryId").val(key);
		}
	}
}	
</script>

</head>
<body>
<div id="contentarea"> 
<script type="text/javascript">
$().ready(function() {
	$('#categoryform').validate();
});
</script>       
	<div id="lb"><div id="rb"><div id="bb"><div id="blc">
	<div id="brc"><div id="tb"><div id="tlc"><div id="trc">
	<div id="content">
		<h1><fmt:message key="navigation.edit"/> <fmt:message key="category.title"/></h1>
		<div class="navitem"><a class="button" href="${pageContext.request.contextPath}/selectThesis?thesisIdKey=${thesis_thesisId}&"><span><img src="includes/images/icons/back.gif" /><fmt:message key="navigation.back"/></span></a></div>
		<form:form id="categoryform" action="${pageContext.request.contextPath}/saveThesisCategories" method="POST" modelAttribute="category">
			<form:hidden id="category_categoryId" path="categoryId"/>
			<table cellpadding="0" cellspacing="0" id="viewTable">
				<tbody>
									
					<tr>
						<td class="label" valign="top">
							<fmt:message key="category.categorydescription.title"/>:
						</td>
						<td>
						 <input type="hidden" id="categoryIds" class="required" />
                    		<div id="categories" style="display:none">
		 				</div>
						<td><%--<input type="text" id="category_categoryDescription"> --%>
							<form:input id="category_categoryDescription" path="categoryDescription" cssStyle="width:300px;"/>
							 <%--<script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "category_categoryDescription",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "<fmt:message key="category.categorydescription.help"/>"}})); </script>
							 --%>
						</td>
					</tr>
				</tbody>
			</table>
			<span class="inputbutton"><input class="savebutton" id="save" type="submit" value="<fmt:message key="navigation.save"/>"/></span>
			<script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'save', event:'onclick'}));</script>
				<input type="hidden" name="thesis_thesisId" value="${thesis_thesisId}">
		</form:form>
		<div class="clear">&nbsp;</div>
	</div>
	</div></div></div></div>
	</div></div></div></div>
</div>

</body>
</html>


